<?php

namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Library\form_builder\src\Form;

class TestController extends BaseController
{
    public function index(){

//        $storage = new \Upload\Storage\FileSystem('/path/to/directory');
//        $file = new \Upload\File('foo', $storage);

        $layout_file=app_path().'/Library/form_builder/src/template/default/layouts/main.html';
          $form=Form::create('add',array(
              Form::text('姓名','name','3232')
                  ->set_props(['placeholder'=>'请设置你的姓名','data-id'=>1]),
              Form::idate('时间','date','')
                  ->set_props(['placeholder'=>'请设置时间','data-id'=>1]),
              Form::input('密码','password','','password')
                  ->set_props([
                      'placeholder'=>'请设置你的姓名'
                  ]),
              Form::selectOne('复选框','select')
                  ->set_options([
                      ['id'=>1,'name'=>'测试'],
                      ['id'=>2,'name'=>'测试2']
                  ]),
              Form::hidden('隐藏','id','','hidden')
                  ->set_props(['placeholder'=>'请设置你的姓名']),
              Form::radio('单选','radio')
                  ->options([['value'=>0,'label'=>'男'],['value'=>1,'label'=>'女']]),
              Form::checkBox('复选','check')
                  ->options([['value'=>0,'label'=>'写作'],['value'=>1,'label'=>'阅读']]),
              Form::Status('复选','check','')
                  ->options([['value'=>0,'label'=>'假'],['value'=>1,'label'=>'真']]),
              Form::textarea('富文本','text','测试')
                  ->set_props(['placeholder'=>'请设置你的姓名','id'=>'LAY_demo_editor']),
          ));
          $form->setLayout($layout_file);

          echo $form->load();die;
    }
    public  function upload(){

//        $storage = new \Upload\Storage\FileSystem(app_path()."/../public/uploads");
//        $file = new \Upload\File('file', $storage);
//
//// Optionally you can rename the file on upload
//        $new_filename = uniqid();
//        $file->setName($new_filename);
//// Validate file upload
//// MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
//        $file->addValidations(array(
//            // Ensure file is of type "image/png"
//            new \Upload\Validation\Mimetype('image/png'),
//
//            //You can also add multi mimetype validation
//            //new \Upload\Validation\Mimetype(array('image/png', 'image/gif'))
//
//            // Ensure file is no larger than 5M (use "B", "K", M", or "G")
//            new \Upload\Validation\Size('5M')
//        ));
//
//// Access data about the file that has been uploaded
//        $data = array(
//            'name'       => $file->getNameWithExtension(),
//            'extension'  => $file->getExtension(),
//            'mime'       => $file->getMimetype(),
//            'size'       => $file->getSize(),
//            'md5'        => $file->getMd5(),
//            'dimensions' => $file->getDimensions()
//        );
//        dd($data);
//// Try to upload file
//        try {
//            // Success!
//            $file->upload();
//
//        } catch (\Exception $e) {
//            // Fail!
//            $errors = $file->getErrors();
//
//        }
//        echo '32';die;
//        $storage = new \Upload\Storage\FileSystem('/path/to/directory');
//        $file = new \Upload\File('foo', $storage);
        return upload('file','uploads');//上传到/web/upload
    }
}
